#region "DbTypeExtensions"

/*
 * ####     Developer Name : Wang Yucai
 * 
 * ####     Development Tool : Microsoft VisualStudio 2010 Ultimate Edition
 * 
 * ####     Create Time : 2014-07-16 15:54:58
 * 
 * ####     Namespace : System.Data
 * 
 * ####     Type Name : DbTypeExtensions
 * 
 * ####     Full Name : System.Data.DbTypeExtensions
 * 
 * ####     Machine Name : GLCHQWYCWINW7
 * 
 * ####     UserName : GUOCOLAND/wangyucai
 * 
 * ####     CLR Version : 4.0.30319.18444
 * 
 * ####     Target Framework Version : 4.0
 */

#endregion

using Masterduner.SourceStudio.Practices.DevelopmentLibrary;

namespace System.Data
{
    /// <summary>
    /// <para>System.Data.DbTypeExtensions</para>
    /// <para>
    /// 为<see cref="DbType"/>提供的扩展方法。
    /// </para>
    /// </summary>
    /// <remarks>
    /// <para>Target Framework Version : 4.0</para>
    /// </remarks>
    public static class DbTypeExtensions
    {
        #region ToSqlDbType
        /// <summary>
        /// 将此<see cref="DbType"/>类型值转换等效的<see cref="SqlDbType"/>值。
        /// </summary>
        /// <param name="current"><see cref="DbType"/>中的一个值。</param>
        /// <returns><see cref="SqlDbType"/>中的一个值。</returns>
        /// <remarks>
        /// 对于某些<see cref="DbType"/>值，可能无法转换为<see cref="SqlDbType"/>值。对于此种情况将会抛出<see cref="ArgumentsExceptionWrapper"/>异常。
        /// </remarks>
        static public SqlDbType ToSqlDbType(this DbType current)
        {
            SqlDbType dbType = SqlDbType.VarChar;
            switch (current)
            {
                case DbType.Byte: dbType = SqlDbType.TinyInt; break;
                case DbType.Int16: dbType = SqlDbType.SmallInt; break;
                case DbType.Int32: dbType = SqlDbType.Int; break;
                case DbType.Int64: dbType = SqlDbType.BigInt; break;
                case DbType.Single: dbType = SqlDbType.Real; break;
                case DbType.Currency: dbType = SqlDbType.Money; break;
                case DbType.Decimal: dbType = SqlDbType.Decimal; break;
                case DbType.Double: dbType = SqlDbType.Float; break;
                case DbType.Guid: dbType = SqlDbType.UniqueIdentifier; break;
                case DbType.Binary: dbType = SqlDbType.Binary; break;
                case DbType.AnsiStringFixedLength: dbType = SqlDbType.Char; break;
                case DbType.AnsiString: dbType = SqlDbType.VarChar; break;
                case DbType.StringFixedLength: dbType = SqlDbType.NChar; break;
                case DbType.String: dbType = SqlDbType.NVarChar; break;
                case DbType.DateTime: dbType = SqlDbType.DateTime; break;
                case DbType.DateTime2: dbType = SqlDbType.DateTime2; break;
                case DbType.DateTimeOffset: dbType = SqlDbType.DateTimeOffset; break;
                case DbType.Date: dbType = SqlDbType.Date; break;
                case DbType.Time: dbType = SqlDbType.Time; break;
                case DbType.Object: dbType = SqlDbType.Variant; break;
                case DbType.Xml: dbType = SqlDbType.Xml; break;
                default: throw new ArgumentsExceptionWrapper();
            }
            return dbType;
        }
        #endregion
    }
}

#region README

/*
 * ####     ©2014 Wang Yucai
 * 
 * ####     Contact me
 *                  
 *                  E-mail : Masterduner@Yeah.net
 *                  Mobile : 13621384677
 *                  QQ : 180261899
 */

#endregion